import 'package:flutter/material.dart';
import 'package:x3_component_core/x3_component_core.dart';

class BusinessDepotStyleItem extends StatelessWidget {
  BusinessDepotStyleItem({Key key, @required this.dataSource}) : super(key: key);

  final dynamic dataSource;

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 72,
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          _buildStyleImageWidget(),
          SizedBox(width: 8.0),
          _buildStyleContent(context),
        ],
      ),
    );
  }

  /// 构建款式图片
  _buildStyleImageWidget() {
    // String styleSKCImg = BaseUtils.getKeyData(dataSource, 'styleSKCImg').toString();
    String styleSKCImg = (dataSource != null && dataSource != "") ? dataSource['styleSKCImg'] ?? "" : "";
    return BaseImageComponent(imageUrl: styleSKCImg, width: 72, height: 72, circular: 4);
  }

  Widget _buildStyleContent(BuildContext context) {
    String styleId = (dataSource != null && dataSource != "") ? dataSource['styleId'] ?? "" : "";
    String styleName = (dataSource != null && dataSource != "") ? dataSource['styleName'] ?? "" : "";
    String colorName = (dataSource != null && dataSource != "") ? dataSource['colorName'] ?? "" : "";
    String colorId = (dataSource != null && dataSource != "") ? dataSource['colorId'] ?? "" : "";
    String jprice = ((dataSource != null && dataSource != "") ? dataSource['jprice'] ?? "" : "").toString();
    return Expanded(
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Text(styleName, style: Theme.of(context).textTheme.bodyText2.apply(fontSizeDelta: 1)),
          if (colorId.isNotEmpty && colorName.isNotEmpty) BaseCopiedText(copiedText: styleId, suffix: '  $colorId/$colorName', needCopyIcon: false),
          if (colorId.isEmpty) BaseCopiedText(copiedText: styleId, suffix: '  $colorName', needCopyIcon: false),
          BaseComponentUtils.buildTextSpanWidget(['吊牌价:', '¥$jprice']),
          BaseComponentUtils.buildHorizontalDivider(),
        ],
      ),
    );
  }
}
